package ubadbtools.deadlockAnalyzer.scheduleRecords;

import ubadbtools.deadlockAnalyzer.database.Database;
import ubadbtools.deadlockAnalyzer.exceptions.TransitionException;
import ubadbtools.deadlockAnalyzer.transactions.TRXState;


public class UnlockRecord extends ScheduleRecord
{
	private String 	item;
	
	public UnlockRecord(String transaction, String item)
	{
		this.transaction = transaction;
		this.item = item;
	}
	
	public String getItem()
	{
		return item;
	}

	public String toString()
	{
		return "UNLOCK(" + item + ")"; 
	}
	
	protected boolean okPrecondition() {
		return getTRX().isLocked(item);
	}
	
	protected void setPoscondition() {
		getTRX().removeLocked(item);
		Database.getInstance().release(item);
	}
	
	protected TRXState getNextTRXState() throws TransitionException {
		return getTRX().getTRXState().unlock();
	}
	
	
}
